//
//  GoodsListHeaderView.m
//  share_business
//
//  Created by 吴于凌 on 2017/9/10.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "GoodsListHeaderView.h"
#import "BSCommon.h"


@interface GoodsListHeaderView()

@property (nonatomic,strong) UIView *line ;



@end

@implementation GoodsListHeaderView



-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setView];
        
    }
    return self;
}

-(void)setView{
    int widht = APPWIDTH / 5 ;
    for (int i = 0; i<5; i++) {
        NSString *title = @"";
        switch (i) {
            case 0:
                title = @"全部";
                break;
            case 1:
                title = @"按销量";
                break;
            case 2:
                title = @"按分享值";
                break;
            case 3:
                title = @"按折扣";
                break;
            case 4:
                title = @"包邮";
                break;
                
            default:
                break;
        }
        UIButton *btn = [BSWidget commonButtonWithFrame:CGRectMake(widht * i, 0, widht, CGRectGetHeight(self.frame)) title:title color:[UIColor grayColor] fontSize:14 target:self action: @selector(clickAction:)];
        btn.tag = 100+i ;
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor colorWithHexString:COLOR_DARK_GRAY] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHexString:COLOR_DARK_GRAY] forState:UIControlStateHighlighted];
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        if (i == 0) {
             [btn setSelected:YES];
        }else {
            [btn setSelected:NO];
        }
       
        [self addSubview:btn];
        
    }
    self.line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.frame), widht, 1)];
    self.line.backgroundColor = [UIColor orangeColor];
    self.line.y = self.height - 1;
    [self addSubview: self.line];
    
}



-(void)clickAction:(UIButton *)sender{
    for (int i =0 ; i<5; i++) {
        UIButton *btn = [self viewWithTag:i+100];
        if (sender.tag == btn.tag) {
            [btn setSelected:YES];
        }else {
            [btn setSelected:NO];
        }
    }
    [UIView animateWithDuration:0.2 animations:^{
        [self.line setCenterX:sender.centerX ];
    } completion:^(BOOL finished) {
//        if (self.delegate) {
//            [self.delegate changeToType:Item3];
//        }
    }];
}
@end
